package com.example.ljw.paperlive.ui.famliy;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import com.example.ljw.paperlive.R;
import com.example.ljw.paperlive.adapter.FamliyViewPagerAdapter;
import com.example.ljw.paperlive.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**家族页面
 * Created by LJW on 2016/11/23.
 */

public class FamliyFragment extends BaseFragment {
    private Context getmContext=getActivity();
    //初始化viewpager
    private ViewPager viewpager_famliy_fragment;
    //初始化tablayout
    private TabLayout tabLayout_famliy_fragment;
    //上下文参数
    private Context mContext=getActivity();
    //fragment的list数组
    private List<Fragment> mListF=new ArrayList<>();

    public FamliyFragment(){

    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        return inflater.inflate(R.layout.fragment_famliy_main,container,false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        tabLayout_famliy_fragment= (TabLayout) view.findViewById(R.id.tabLayout_famliy_ragment);
        viewpager_famliy_fragment= (ViewPager) view.findViewById(R.id.viewpager_famliy_fragment);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initViewpager();
    }

    private void initViewpager() {
        //从arrays资源获取栏目数组
        String [] arrTabs=getActivity().getResources().getStringArray(R.array.arrTabsFamliy);
        for (int i=0;i<arrTabs.length;i++){
            FamliyInnerFragment fragment=FamliyInnerFragment.newInstance(i+1);
            mListF.add(fragment);

        }
        viewpager_famliy_fragment.setOffscreenPageLimit(3);
        //位Viewpager设置适配器
        FamliyViewPagerAdapter fvp=new FamliyViewPagerAdapter(getChildFragmentManager(),mListF,arrTabs);
        viewpager_famliy_fragment.setAdapter(fvp);
        tabLayout_famliy_fragment.setTabMode(TabLayout.MODE_FIXED);
        tabLayout_famliy_fragment.setupWithViewPager(viewpager_famliy_fragment);

    }



}
